package com.crm.serviceImpl;


import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;

import com.crm.common.util.Page;
import com.crm.entity.Customer;
import com.crm.entity.QueryVo;

import com.crm.mapper.CustomerMapper;
import com.crm.service.CustomerService;
@Service
public class CustomerServiceImpl implements CustomerService{
	@Autowired
	private CustomerMapper customerMapper;

	
	public Page<Customer> selectPageByQueryVo(QueryVo queryVo){
		Page<Customer> page = new Page<Customer>();
		queryVo.setRows(5);//每页显示5条记录
		page.setSize(queryVo.getRows());
		if (null != queryVo) {
			if(null != queryVo.getPage()) {
				page.setPage(queryVo.getPage());
				queryVo.setStartRows((queryVo.getPage()-1)*queryVo.getRows());//设置sql查询起始条数 limi queryVo.getStartRows(),queryVo.getRows()
			}
			if (null != queryVo.getCustName() && !"".equals(queryVo.getCustName().trim())) {
				queryVo.setCustName(queryVo.getCustName().trim());
			}
			if (null != queryVo.getCustSource()&& !"".equals(queryVo.getCustSource().trim())) {
				queryVo.setCustSource(queryVo.getCustSource().trim());
			}
			if (null != queryVo.getCustIndustry() && !"".equals(queryVo.getCustIndustry().trim())) {
				queryVo.setCustIndustry(queryVo.getCustIndustry().trim());
			}
			if (null != queryVo.getCustLevel() && !"".equals(queryVo.getCustLevel().trim())) {
				queryVo.setCustLevel(queryVo.getCustLevel().trim());
			}
		}
		
		
		page.setTotal(customerMapper.totalCustomer(queryVo));
		
		page.setRows(customerMapper.selectCustomerListByQueryVo(queryVo));
		
		return page;
	}


	@Override
	public int delCustomerById(Long id) {
		return customerMapper.delCustomerById(id);
	}


	@Override
	public int updateCustomerById(Customer customer) {
		return customerMapper.updateCustomerById(customer);
	}


	@Override
	public Customer selectCustomerById(Long id) {
		return customerMapper.selectCustomerById(id);
	}


	



}
